home *** CD-ROM | disk | FTP | other *** search
- public final class SearchSieve {
- private int patternIndex;
- private int textIndex;
- private int mostRecentMatchIndex;
- private String patternString;
- private char[] pattern;
- private int patternLength;
- private int numberOfMatches;
- private boolean exactMatchesOnly;
- private char prevc;
- private char[] buffer;
- private int bufferLength;
- private boolean buffering;
- private char[] swapSpace;
- private static boolean[] wordCharTable = new boolean[256];
-
- public SearchSieve(String var1, boolean var2) {
- this.setPattern(var1, var2);
- }
-
- public final void setPattern(String var1, boolean var2) {
- this.exactMatchesOnly = var2;
- this.patternString = var1;
- this.pattern = var1.toCharArray();
- this.patternLength = this.pattern.length;
- this.buffer = new char[this.patternLength];
- this.swapSpace = new char[this.patternLength];
- this.reset();
- }
-
- public final void reset() {
- this.textIndex = -1;
- this.mostRecentMatchIndex = -1;
- this.patternIndex = 0;
- this.numberOfMatches = 0;
- this.prevc = 0;
- this.bufferLength = 0;
- this.buffering = false;
- }
-
- public final String getPattern() {
- return this.patternString;
- }
-
- public final int getPatternLength() {
- return this.patternLength;
- }
-
- public final int getIndexInText() {
- return this.textIndex;
- }
-
- public final int getMostRecentMatchIndex() {
- return this.mostRecentMatchIndex;
- }
-
- public final int getNumberOfMatches() {
- return this.numberOfMatches;
- }
-
- public final boolean addChar(char var1) {
- boolean var2 = false;
- boolean var3 = false;
- ++this.textIndex;
- if (this.patternLength < 1) {
- return false;
- } else {
- if (this.exactMatchesOnly) {
- if (this.patternIndex == 0) {
- if (var1 == this.pattern[0] && !isWordChar(this.prevc)) {
- ++this.patternIndex;
- }
- } else if (this.patternIndex != this.patternLength) {
- if (var1 != this.pattern[this.patternIndex]) {
- this.patternIndex = 0;
- var3 = true;
- } else {
- ++this.patternIndex;
- }
- } else {
- if (!isWordChar(var1)) {
- var2 = true;
- }
-
- this.patternIndex = 0;
- var3 = true;
- }
- } else {
- if (var1 != this.pattern[this.patternIndex]) {
- this.patternIndex = 0;
- var3 = true;
- } else {
- ++this.patternIndex;
- }
-
- if (this.patternIndex == this.patternLength) {
- this.patternIndex = 0;
- var3 = true;
- var2 = true;
- }
- }
-
- if (this.patternIndex > 1 && !this.buffering && var1 == this.pattern[0]) {
- if (!this.exactMatchesOnly || this.exactMatchesOnly && !isWordChar(this.prevc)) {
- this.buffering = true;
- this.buffer[0] = var1;
- this.bufferLength = 1;
- }
- } else if (this.buffering) {
- if (var1 != this.pattern[this.bufferLength]) {
- this.bufferLength = 0;
- this.buffering = false;
- } else {
- this.buffer[this.bufferLength] = var1;
- ++this.bufferLength;
- }
- }
-
- if (var3 && this.bufferLength > 0) {
- this.eatTheBuffer();
- }
-
- this.prevc = var1;
- if (var2) {
- ++this.numberOfMatches;
- this.mostRecentMatchIndex = this.textIndex - this.patternLength + 1;
- if (this.exactMatchesOnly) {
- this.mostRecentMatchIndex += -1;
- }
- }
-
- return var2;
- }
- }
-
- public String toString() {
- return this.getPattern();
- }
-
- private final void eatTheBuffer() {
- this.patternIndex = 0;
- System.arraycopy(this.buffer, 0, this.swapSpace, 0, this.bufferLength);
- int var1 = this.bufferLength;
- this.bufferLength = 0;
- this.buffering = false;
-
- for(int var2 = 0; var2 < var1; ++var2) {
- this.addChar(this.swapSpace[var2]);
- }
-
- }
-
- public static final boolean isWordChar(int var0) {
- return var0 >= 0 && var0 <= 255 ? wordCharTable[var0] : false;
- }
-
- public static final void setWordChar(char var0, boolean var1) {
- if (var0 != 0 && var0 <= 255) {
- wordCharTable[var0] = var1;
- } else {
- throw new IllegalArgumentException("Out of range.");
- }
- }
-
- static {
- for(int var0 = 0; var0 < 256; ++var0) {
- if ((var0 < 65 || var0 > 90) && (var0 < 97 || var0 > 122) && (var0 < 48 || var0 > 57) && var0 < 192) {
- wordCharTable[var0] = false;
- } else {
- wordCharTable[var0] = true;
- }
- }
-
- }
- }
-